package org.jetlinks.pro.clickhouse.engine;

import lombok.Getter;
import lombok.Setter;
import org.hswebframework.web.bean.FastBeanCopier;

import java.util.StringJoiner;

@Getter
@Setter
public class ReplicatedMergeTree extends MergeTree {

    private String zooPath = "/clickhouse/tables/{shard}/{table}";

    private String replicaName = "{replica}";

    @Override
    public String getEngine(String table) {
        StringJoiner joiner = new StringJoiner(",", "ReplicatedMergeTree(", ")");
        joiner.add("'"+zooPath.replace("{table}", table)+"'");
        joiner.add("'"+replicaName.replace("{table}", replicaName)+"'");
        return joiner.toString();
    }

    public ReplicatedMergeTree zooPath(String zooPath) {
        this.zooPath = zooPath;
        return this;
    }

    public ReplicatedMergeTree replicaName(String replicaName) {
        this.replicaName = replicaName;
        return this;
    }

    @Override
    public ReplicatedMergeTree orderBy(String orderBy) {
        super.orderBy(orderBy);
        return this;
    }

    @Override
    public ReplicatedMergeTree partitionBy(String partitionBy) {
        super.partitionBy(partitionBy);
        return this;
    }

    @Override
    public ReplicatedMergeTree primaryKey(String primaryKey) {
        super.primaryKey(primaryKey);
        return this;
    }

    @Override
    public ReplicatedMergeTree sampleBy(String sampleBy) {
        super.sampleBy(sampleBy);
        return this;
    }

    @Override
    public ReplicatedMergeTree distributed(String cluster) {
        super.distributed(cluster);
        return this;
    }

    @Override
    public ReplicatedMergeTree cluster(String cluster) {
        super.cluster(cluster);
        return this;
    }

    public ReplicatedMergeTree copy() {
        return FastBeanCopier.copy(this, new ReplicatedMergeTree());
    }
}
